/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.workforce.common.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

/**
 *
 * @author neo
 */
public class FieldHiddenTag extends TagSupport {

    protected String id;
    protected String name;
    protected String value;
    protected String param;

    @Override
    public int doStartTag() throws JspException {
        JspWriter out = pageContext.getOut();
        StringBuffer s = new StringBuffer();
        s.append("<input type=\"hidden\" ");
        if( id != null ) {
            s.append("id=\"").append(id).append("\" ");
        }
        if( name != null ) {
            s.append("name=\"").append(name).append("\" ");
        }
         if( value != null ) {
            s.append("value=\"").append(value).append("\" ");
        } else {
            if( param != null ) {
                String sp = (String)pageContext.getAttribute(param, PageContext.PAGE_SCOPE);
                s.append("value=\"").append(sp).append("\" ");
            }
        }
        s.append(">");
        try {
            out.print(s.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return SKIP_BODY;
    }

    @Override
    public int doEndTag() throws JspException {
        return super.doEndTag();
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public void setParam(String param) {
        this.param = param;
    }
    
}
